package com.cloud.pay.payment;

import com.cloud.common.bean.ResultInfo;
import com.cloud.common.util.JsonUtils;
import com.cloud.message.MessageProvider;
import com.cloud.message.dto.MessageDTO;
import com.cloud.pay.entity.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PayNotifyer {

    private static final String TOPIC = "PayNotify";

    @Autowired
    private MessageProvider messageProvider;

    public ResultInfo<String> send(Payment payment) {
        MessageDTO message = new MessageDTO();
        message.setTopic(TOPIC);
        message.setContent(JsonUtils.toJSONString(payment));
        message.setHashKey(payment.getTradeNo());
        return messageProvider.send(message);
    }
}
